﻿<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.zaofan.bean.Lable"%>
<%@page import="com.zaofan.cache.CacheManage"%>
<%@page import="com.zaofan.constant.LableConstant"%>
<%@page import="com.zaofan.bean.Admin"%>
<%@page import="com.zaofan.bean.AdminType"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	String contextPath = request.getContextPath();
Admin admin = (Admin)session.getAttribute("admin");
if(admin == null){
	response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
	return;
	}
if(admin.getType() != AdminType.admin.ordinal() &&  admin.getType() != 4){
	response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
	return;
}
	String id = request.getParameter("id");
	String action = "add";
	if(id == null){
		id="";
		action = "add";
	}else{
		action = "update";
	}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>增加商铺</title>
<link href="<%=contextPath%>/admin/css/base.css" rel="stylesheet" />
<link href="<%=contextPath%>/admin/assets/css/bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/font-awesome.min.css" />
<!--[if IE 7]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome-ie7.min.css" />
<![endif]-->
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace-rtl.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace-skins.min.css" />
<!--[if lte IE 8]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-ie.min.css" />
<![endif]-->
<script src="<%=contextPath%>/admin/assets/js/ace-extra.min.js"></script>
<!--[if lt IE 9]>
	<script src="<%=contextPath%>/admin/assets/js/html5shiv.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/bootstrap-timepicker.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/chosen.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/css/uploadify.css" />
<script type="text/javascript">  
       var contextPath='<%=contextPath%>';
       var action='<%=action%>';
       var id='<%=id%>';
</script>
</head>
<body style="background-color: #fff;">
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
			try {
				ace.settings.check('breadcrumbs', 'fixed')
			} catch (e) {
			}
		</script>
		<ul class="breadcrumb">
			<li><i class="icon-home home-icon"></i> <a
				href="<%=contextPath%>/admin/admin/index.jsp">首页</a></li>
			<li class="active">管理</li>
		</ul>
	</div>
	<div class="page-content">
		<div class="page-header">
			<h1>
				管理 <small> <i class="icon-double-angle-right"> 店铺添加 </i>
				</small>
			</h1>
		</div>
		<!-- /.page-header -->
		<div class="row" style="height: 100%">
			<div class="col-xs-12">
				<a href="javascript:history.go(-1);" class="btn btn-primary" role="button">返回</a>
				<div class="alert alert-info" role="alert">店铺添加</div>
				<div class="popover-inner" style="">
					<div class="popover-content" id="" style="">
						<form class="form-horizontal" style="padding-top: 10px;"
							method="post" id="shopForm">
							<input type="hidden" value="<%=id %>" name="id" />
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">店铺名称：</label>
								<div class="col-sm-9">
									<input name="shopName" id="shopName" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">店铺编码：</label>
								<div class="col-sm-9">
									<input name="shopCode" id="shopCode" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group " >
								<label for="" class="col-sm-2 control-label">营业时间：</label>
								<div class="col-sm-9 bootstrap-timepicker">
									<input id="beginTime" name="beginTime" type="text" class="form-control" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">结束时间：</label>
								<div class="col-sm-9 bootstrap-timepicker">
									<input id="endTime" name="endTime" type="text" class="form-control" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">店铺描述：</label>
								<div class="col-sm-9">
									<input name="shopDes" id="shopDes" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">快递费：</label>
								<div class="col-sm-9">
									<input name="express" id="express" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">起送价：</label>
								<div class="col-sm-9">
									<input name="minPrice" id="minPrice" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<%
								application.setAttribute("shopType", CacheManage.lables.get(LableConstant.lable_shop_type));
								application.setAttribute("expressType", CacheManage.lables.get(LableConstant.lable_express_type));
								application.setAttribute("payType", CacheManage.lables.get(LableConstant.lable_pay_type));
								application.setAttribute("shopShowType", CacheManage.lables.get(LableConstant.lable_shop_show_type));
							%>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">商铺类型：</label>
								<div class="col-sm-9">
									<c:forEach items="${shopType }" var="s">
										<input type="radio" name="lableId" value="${s.id }" />${s.name }&nbsp;&nbsp;
									</c:forEach>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">配送类型：</label>
								<div class="col-sm-9">
									<c:forEach items="${expressType }" var="e">
										<input type="radio" name="expressLableId" value="${e.id }" />${e.name }&nbsp;&nbsp;
									</c:forEach>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">商家展示类型：</label>
								<div class="col-sm-9">
									<c:forEach items="${shopShowType }" var="e">
										<input type="radio" name="showLableId" value="${e.id }" />${e.name }&nbsp;&nbsp;
									</c:forEach>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">支付类型：</label>
								<div class="col-sm-9">
									<c:forEach items="${payType }" var="p">
										<input type="checkbox" name="payLableId" value="${p.id }" />${p.name }&nbsp;&nbsp;
									</c:forEach>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<input type="hidden" value="" id="cityId" name="cityId" />
							<input type="hidden" value="" id="areaId" name="areaId" />
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">所在城市：</label>
								<div class="col-sm-9" id="cityInfo">
									<select style="width:150px;" id="cityList" >
										
				  					</select>
				  					
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">覆盖类型：</label>
								<div class="col-sm-9">
									<input type="radio" value="0" name="coverType" /> 指定大楼
									<input type="radio" value="1" name="coverType" /> 全城配送
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">覆盖区域：</label>
								<div class="col-sm-9" id="builders">
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">排序：</label>
								<div class="col-sm-9" >
									<input name="sort" id="sort" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<input type="hidden" value="" name="shopImage" id="shopImage" />
								<label for="" class="col-sm-2 control-label">商品图片：</label>
								<div class="col-sm-9">
									<div id="imageProduct" style="display:none;">
										<img src="" width="50" height="50" />
									</div>
									<br/>
									<input type="file" id="image" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<input type="hidden" value="" id="cityName" />
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">店铺地址：</label>
								<div class="col-sm-9">
									<input name="address" id="address" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*请填写详细地址</span>
							</div>
							<div class="form-group" style="display:none;" id="jingInfo">
								<label for="" class="col-sm-2 control-label">店铺经纬度：</label>
								<input type="hidden" value="" name="lon" id="lon" />
								<input type="hidden" value="" name="lat" id="lat" />
								<div class="col-sm-9">
									<input id="addressInfo" class="form-control" value=""  readOnly="readOnly"/>
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">是否开启：</label>
								<div class="col-sm-9">
									<input type="radio" value="1" name="isOpen" /> 是
									<input type="radio" value="0" name="isOpen" /> 否
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" style="display:none;" id="noOpenInfo">
								<label for="" class="col-sm-2 control-label">介绍地址：</label>
								<div class="col-sm-9">
									<input id="showUrl" class="form-control" value="" name="showUrl" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" style="display:none;" id="noOpenImage">
								<input type="hidden" value="" name="closeImage" id="closeImage" />
								<label for="" class="col-sm-2 control-label">暂未开启图片：</label>
								<div class="col-sm-9">
									<div id="imageProduct1" style="display:none;">
										<img src="" width="50" height="50" />
									</div>
									<br/>
									<input type="file" id="closeImage1" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							
							<div class="form-group"  >
								<input type="hidden" value="" name="timeoutImage" id="timeoutImage" />
								<label for="" class="col-sm-2 control-label">店铺点餐过时图片：</label>
								<div class="col-sm-9">
									<div id="imageProduct2" style="display:none;">
										<img src="" width="50" height="50" />
									</div>
									<br/>
									<input type="file" id="closeImage2" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							
						</form>
					</div>
					<div class="popover-footer"
						style="overflow: hidden; text-align: center;">
						<button type="button" class="btn btn-primary"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="cancel">
							<i class="icon-ok"></i>取消
						</button>
						<button type="button" class="btn btn-danger"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="save">
							<i class="icon-edit"></i>保存
						</button>

					</div>
				</div>
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
	</div>
	<div id="loading"
		style="width: 32px; height: 32px; position: fixed; left: 40%; top: 40%; display: none;">
		<img src="<%=contextPath%>/admin/assets/css/images/loading.gif"
			width="32" height="32" />
	</div>
	<div class="popover"
		style="z-index: 9999; width: 150px; position: fixed; left: 40%; top: 40%;">
		<div class="arrow"></div>
		<div class="popover-inner">
			<h3 class="popover-title">操作提示</h3>
			<div class="popover-content" id="popover-content">
				<p>操作成功</p>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"/script>");
	</script>
	<script type="text/javascript">
		window.jQuery
				|| document
						.write("<script src='<%=contextPath%>/admin/assets/js/jquery-2.0.3.min.js'>"
								+ "<"+"script>");
	</script>

	<!--[if IE]>
		<script type="text/javascript">
			window.jQuery || document.write("<script src='<%=contextPath%>/admin/assets/js/jquery-1.10.2.min.js'>"+"<"+"script>");
		</script>
	<![endif]-->
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"script>");
	</script>
	<script src="<%=contextPath%>/admin/assets/js/bootstrap.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/typeahead-bs2.min.js"></script>

	<!--[if lte IE 8]>
		  <script src="assets/js/excanvas.min.js"></script>
	<![endif]-->
	<script
		src="<%=contextPath%>/admin/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.ui.touch-punch.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.slimscroll.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.easy-pie-chart.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.sparkline.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace-elements.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace.min.js"></script>
	<script src="<%=contextPath%>/admin/js/common.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery-form.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/date-time/bootstrap-timepicker.min.js"></script>
	<script src="<%=contextPath%>/admin/js/jquery.uploadify.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>

	<script type="text/javascript">
		init();
		
		function init(){
			$('#beginTime').timepicker({
				minuteStep: 1,
				showSeconds: true,
				showMeridian: false
			}).next().on(ace.click_event, function(){
				$(this).prev().focus();
			});
			
			$('#endTime').timepicker({
				minuteStep: 1,
				showSeconds: true,
				showMeridian: false
			}).next().on(ace.click_event, function(){
				$(this).prev().focus();
			});
			
			$("input[type='radio'][name='isOpen']").change(function(){
				var val = $("input[type='radio'][name='isOpen']:checked").val();
				if(val == 1){
					$("#noOpenInfo").hide();
					$("#noOpenImage").hide();
				}else{
					$("#noOpenInfo").show();
					$("#noOpenImage").show();
				}
			});
			
			$("#loading").show();
			$.ajax({
				url : contextPath + '/city',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'open',
				},
				success : function(rs, textStatus, jqXHR) {
					$("#loading").hide();
					if (rs.success) {
						var options = "<option value='-1'>请选择所在城市</option>";
						var data = rs.data;
						for(var i = 0 ; i < data.length ; i++){
							options += '<option value='+data[i].id+'>'+data[i].cityName+'</option>';
						}
						$("#cityList").append(options);
						$("#cityList").change(function(){
							var val = $(this).val();
							if(val == -1){
								$("#cityName").val("");
								$("#cityId").val("0");
								$("#areaId").val("0");
								$("#areaList").remove();
							}else{
								$("#cityName").val($(this).find("option:selected").text());
								$("#cityId").val(val);
								$("#areaId").val("0");
								$("#areaList").remove();
								getAreaInfo();
							}
						});
					} else{
						showMessage(rs.msg);
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			});
			
		}
		
		
		function getAreaInfo(){
			$("#loading").show();
			$.ajax({
				url : contextPath + '/area',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'open',
					cityId:$("#cityId").val()
				},
				success : function(rs, textStatus, jqXHR) {
					$("#loading").hide();
					if (rs.success) {
						var options = '<select style="width:150px;" id="areaList" ><option value="-1">请选择所在区域</option>';
						var data = rs.data;
						for(var i = 0 ; i < data.length ; i++){
							options += '<option value='+data[i].id+'>'+data[i].areaName+'</option>';
						}
						options += "</select>";
						$("#cityInfo").append(options);
						if($("#areaId").val() != ""){
							$("#areaList").val($("#areaId").val());
						}
						$("#areaList").change(function(){
							var val = $(this).val();
							if(val == -1){
								$("#areaId").val("0");
								$("#builders").empty();
							}else{
								$("#areaId").val(val);
								getBuilder();
							}
						});
					} else{
						showMessage(rs.msg);
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			});
			
		}
		
		
		function getBuilder(old){
			$("#loading").show();
			$.ajax({
				url : contextPath + '/builder',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'open',
					cityId:$("#cityId").val(),
					areaId:$("#areaId").val()
				},
				success : function(rs, textStatus, jqXHR) {
					$("#loading").hide();
					if (rs.success) {
						$("#builders").empty();
						var options = '';
						var data = rs.data;
						for(var i = 0 ; i < data.length ; i++){
							options += '<input name="builderIds" type="checkbox" value='+data[i].id+' />'+data[i].builderName+'&nbsp;&nbsp;';
						}
						$("#builders").append(options);
						if(old != null && old != ""){
							for(var i = 0 ; i < old.length ; i++){
								$("input[name='builderIds'][value='"+old[i].builderId+"']").prop("checked","checked");
							}
						}
					} else{
						showMessage(rs.msg);
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			});
			
		}
	
	
		$("#save").bind("click", function() {
			if ($("#shopName").val() == "") {
				showMessage("请输入店铺名称!!!");
				return;
			}
			if ($("#shopCode").val() == "") {
				showMessage("请输入店铺编码!!!");
				return;
			}
			if ($("#beginTime").val() == "") {
				showMessage("请输入开始营业时间!!!");
				return;
			}

			if ($("#endTime").val() == "") {
				showMessage("请输入结束时间!!!");
				return;
			}
			if ($("#shopDes").val() == "") {
				showMessage("请输入商铺的简单描述!!!");
				return;
			}
			if ($("#express").val()=="") {
				showMessage("请输入商铺的快递费!!!");
				return;
			}
			if (isNaN($("#express").val() )) {
				showMessage("商铺的快递费必须为数字!!!");
				return;
			}
			if ($("#minPrice").val() == "") {
				showMessage("请输入商铺起送价格!!!");
				return;
			}
			if (isNaN($("#minPrice").val())) {
				showMessage("商铺起送价格必须为数字!!!");
				return;
			}
			if($("input[name='lableId']:checked").length == 0){
				showMessage("请选择商铺类型!!!");
				return;
			}
			if($("input[name='expressLableId']:checked").length == 0){
				showMessage("请选择商铺配送类型!!!");
				return;
			}
			if($("input[name='expressLableId']:checked").length == 0){
				showMessage("请选择商铺配送类型!!!");
				return;
			}
			if($("input[name='payLableId']:checked").length == 0){
				showMessage("请至少选择一个商铺的支付方式!!!");
				return;
			}
			if($("input[name='showLableId']:checked").length == 0){
				showMessage("请至少选择一个商铺的支付方式!!!");
				return;
			}
			if ($("#cityId").val() == "") {
				showMessage("请选择商铺的城市信息!!!");
				return;
			}
			
			if($("input[name='coverType']:checked").val() == 0){
				if ($("#areaId").val() == "") {
					showMessage("请选择商铺的区域信息!!!");
					return;
				}
				if($("input[name='builderIds']:checked").length == 0){
					showMessage("请至少选择一个商铺的支持的大楼!!!");
					return;
				}
			}
			
			$("#loading").show();
			$("#shopForm").ajaxSubmit({
				type : "POST",
				url : contextPath + '/shop?action=' + action,
				dataType : 'json',
				success : function(data) {
					if (data.success) {
						showMessage(data.msg);
						setTimeout(function() {
							window.location.href = "shopList.jsp";
						}, 2000);
					} else {
						showMessage(data.msg);
					}
					$("#loading").hide();
				},
				error : function(msg) {
					$("#loading").hide();
					showMessage("操作失败");
				}
			});
		});
		$("#address").focus(function(){
			var val = $("#cityId").val();
			if(val == 0){
				showMessage("请选择商品城市信息");
				$(this).blur();
				return;
			}
		});
		$("#address").blur(function(){
			var val = $(this).val();
			if(val == ""){
				return ;
			}
			$.ajax({
				url : contextPath + '/position',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'location',
					address:val,
					city:$("#cityName").val()
				},
				success : function(rs, textStatus, jqXHR) {
					$("#loading").hide();
					if (rs.success) {
						$("#jingInfo").show();
						$("#lon").val(rs.data.result.location.lng);
						$("#lat").val(rs.data.result.location.lat);
						$("#addressInfo").val("经度信息:"+ rs.data.result.location.lng + ",纬度信息:" + rs.data.result.location.lat);
					} else{
						showMessage(rs.msg);
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			}); 
			
		});
		$("#image").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#shopImage").val(imgsrc);
					$("#imageProduct").show();
					$("#imageProduct").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		$("#closeImage1").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#closeImage").val(imgsrc);
					$("#imageProduct1").show();
					$("#imageProduct1").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		$("#closeImage2").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#timeoutImage").val(imgsrc);
					$("#imageProduct2").show();
					$("#imageProduct2").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		$(function(){
			if(action == "update"){
				$.ajax({
					url : contextPath + '/shop',
					type : "POST",
					dataType : 'json',
					data : {
						action : 'get',
						id:id
					},
					success : function(rs, textStatus, jqXHR) {
						$("#loading").hide();
						if (rs.success) {
							var data = rs.data;
							$("#shopName").val(data.shopName);
							$("#shopCode").val(data.shopCode);
							$("#beginTime").val(data.beginTime);
							$("#endTime").val(data.endTime);
							$("#shopDes").val(data.shopDes);
							$("#express").val(data.express);
							$("#minPrice").val(data.minPrice);
							$("input[name='lableId'][value='"+data.lableId+"']").prop("checked","checked");
							$("input[name='expressLableId'][value='"+data.expressLableId+"']").prop("checked","checked");
							$("input[name='showLableId'][value='"+data.showLableId+"']").prop("checked","checked");
							$("input[name='coverType'][value='"+data.coverType+"']").prop("checked","checked");
							$("input[name='isOpen'][value='"+data.isOpen+"']").prop("checked","checked");
							if(data.isOpen == 1){
								$("#closeImage").val("");
								$("#noOpenInfo").hide();
								$("#noOpenImage").hide();
							}else{
								$("#showUrl").val(data.showUrl);
								$("#closeImage").val(data.closeImage);
								$("#noOpenInfo").show();
								$("#noOpenImage").show();
								$("#imageProduct1").show();
								$("#imageProduct1").find("img").attr("src",contextPath + data.closeImage);
							}
							var lables = data.payLables;
							if(lables != null && lables.length > 0){
								for(var i = 0 ; i < lables.length ;i++){
									$("input[name='payLableId'][value='"+lables[i].lableId+"']").prop("checked","checked");
								}
							}
							$("#address").val(data.address);
							$("#sort").val(data.sort);
							$("#shopImage").val(data.shopImage);
							$("#imageProduct").show();
							$("#imageProduct").find("img").attr("src",contextPath + data.shopImage);
							if(data.timeoutImage){
								$("#timeoutImage").val(data.timeoutImage);
								$("#imageProduct2").show();
								$("#imageProduct2").find("img").attr("src",contextPath + data.timeoutImage);
							}
							$("#cityList").val(data.cityId);
							$("#cityId").val(data.cityId);
							if(data.coverType == 0){
								$("#areaId").val(data.areaId);
								getAreaInfo();
								getBuilder(data.builders);
							}
						} else{
							showMessage(rs.msg);
						}
						$("#loading").hide();
					},
					error : function() {
						$("#loading").hide();
						showMessage("请稍后再试");
					}
				}); 
			}
		});
	</script>
</body>
</html>